<?php
session_start();

/*
 * Cheks if the logged in user owsn the page with the POST-id.
 *
 * Returns JSON respond true or false
 *
 */

// Return json encoded data
header ('Content-type: application/json');

require_once '../core/db.php';

if(isset($_SESSION['user'])) {
	$sql = "SELECT userId FROM sitePages WHERE pageId=:id";
	$query = $db -> prepare($sql);
	$query -> bindParam(':id', $_POST['id']);
	$query -> execute();
	$res = $query -> fetch();
	if($res['userId'] == $_SESSION['user']) {
		die(json_encode(array("respond" => "true")));
	}
	else {
		die(json_encode(array("respond" => "false")));
	}
}
else {
	die(json_encode(array("respond" => "false")));
}